<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{$tpshop_config['shop_info_store_title']}</title>
<meta http-equiv="keywords" content="{$tpshop_config['shop_info_store_keyword']}" />
<meta name="description" content="{$tpshop_config['shop_info_store_desc']}" />
<link rel="stylesheet" href="__STATIC__/css/user.css" type="text/css">
</head>
<body>


       		<div class="wel-log">{$Think.lang.login}</div>
		
        <form action="{:U('Home/User/do_login')}" method="post">
            <input type="hidden" name="referurl" id="referurl" value="{$referurl}">
            <div class="login-x">
                <div>
                    <table class="pa-10-0" width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <td><input class="zc-text zc_u" type="text" id="username" name="username"  onkeydown="if(event.keyCode==13){checkSubmit();}" placeholder="{$Think.lang.loginuser}"/></td>
                        </tr>
                        <tr>
                            <td><input class="zc-text zc_p" name="password" id="password" type="password" onKeyDown="if(event.keyCode==13){checkSubmit();}" placeholder="{$Think.lang.loginpsw}"/></td>
                        </tr>
                        <tr>
                            <td>
                                <input class="zc-text zc_code" onKeyDown="if(event.keyCode==13){checkSubmit();}" type="text" name="verify_code" id="verify_code" placeholder="{$Think.lang.logincode}"/>
                                <img id="verify_code_img"  src="{:U('Home/User/verify')}"  onclick="verify(this)" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input class="ma-ri-5 fo-fa-ta" type="checkbox" id="remember_name" style="vertical-align:middle;"/><label for="remember_name">{$Think.lang.loginremebe}</label>
                              <div class="f_r_login"><a href="{:U('Home/User/reg')}">{$Think.lang.loginreg}</a>&nbsp;&nbsp;<a href="{:U('User/forget_pwd')}" style="display: none;" >{$Think.lang.loginforpsw}</a></div>
                            </td>
                        </tr>
                        <tr>
                            <td><input type="button" class="login" onClick="checkSubmit()" value="{$Think.lang.loginsubmit}"></td>
                        </tr>
                    </table>
                </div>
            </div>
        </form>
		
		<div class="otherlogin_line"></div>
		
        <span class="otherlogin">{$Think.lang.loginother}</span>
		<div class="other_login_fs">
			<span><a class="hezuoz" href="{:U('LoginApi/login',array('oauth'=>'alipay'))}"><i class="zfb"></i>支付宝</a></span>
			<span><a class="hezuoz" href="{:U('LoginApi/login',array('oauth'=>'qq'))}"><i class="qq"></i>QQ</a></span>
		</div>
  



<script>
    function verify(){
       $('#verify_code_img').attr('src','/index.php?m=Home&c=User&a=verify&r='+Math.random());
    }
    
	function checkSubmit()
	{
		var username = $.trim($('#username').val());
		var password = $.trim($('#password').val());
		var referurl = $('#referurl').val();
		var verify_code = $.trim($('#verify_code').val());
		if(username == ''){
			$.artTip('郵箱/用戶名/已驗證手機號不能為空.', 800);
			return false;
		}
		if(!checkMobile(username) && !checkEmail(username)){
			
			$.artTip('用戶名格式不匹配', 800);
			return false;
		}
		if(password == ''){
			$.artTip('密碼不能為空', 800);
			return false;
		}
		if(verify_code == ''){
			$.artTip('驗證碼不能為空', 800);
			return false;
		}
		
		$.ajax({
			type : 'post',
			url : '/index.php?m=Home&c=User&a=do_login&t='+Math.random(),
			data : {username:username,password:password,referurl:referurl,verify_code:verify_code},
			dataType : 'json',
			success : function(res){
				if(res.status == 1){
					window.location.href = res.url;
				}else{
					$.artTip(res.msg, 800);
					verify();
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				//showErrorMsg('網絡失敗，請刷新頁面後重試');
				$.artTip('網絡失敗，請刷新頁面後重試', 800);
			}
		})
		
	}
	
    function checkMobile(tel) {
        var reg = /(^1[3|4|5|7|8][0-9]{9}$)/;
        if (reg.test(tel)) {
            return true;
        }else{
            return false;
        };
    }
    
    function checkEmail(str){
        var reg = /^[a-z0-9]([a-z0-9\\.]*[-_]{0,4}?[a-z0-9-_\\.]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+([\.][\w_-]+){1,5}$/i;
        if(reg.test(str)){
            return true;
        }else{
            return false;
        }
    }
    
    function showErrorMsg(msg){
    	alert(msg);
    }
</script>
</div>
</body>
</html>